const db = require('./db.js');


const modelMap = `          m.menu_id AS menuId,
                            m.menu_name AS menuName,
                            parent_id parentId,
                            order_num orderNum,
                            menu_type menuType,
                            path,
                            component,
                            visible,
                            m.status,
                            perms,
                            icon,
                            is_cache AS isCache,
                            is_frame AS isFrame`
module.exports = {
    GetMenusByUserId: async (userId) => {
        const sql = `SELECT
                        ${modelMap}
                        FROM
                        sys_user_role ur
                        LEFT JOIN sys_role r ON ur.role_id = r.role_id
                        LEFT JOIN sys_role_menu rm ON rm.role_id = r.role_id
                        LEFT JOIN sys_menu m ON rm.menu_id = m.menu_id
                        WHERE
                        user_id = ?
                        AND r.del_flag = 0`
        return await db.query(sql, [userId])
    }

}
